package com.gitee.minimalismstyle.fresh.common.dubbo.util

import com.gitee.minimalismstyle.fresh.common.core.spring.SpringContextUtils
import org.apache.dubbo.config.spring.beans.factory.annotation.ReferenceAnnotationBeanPostProcessor

object DubboUtils {
    fun  <T> getBean(clazz: Class<T>): T?{
        val dubboContext = SpringContextUtils.getBean(ReferenceAnnotationBeanPostProcessor::class)
        val referenceBean = dubboContext.referenceBeans.find {it.objectType == clazz}
        return referenceBean?.get() as T
    }

    fun  <T> getBean(clazzName: String): T?{
        val dubboContext = SpringContextUtils.getBean(ReferenceAnnotationBeanPostProcessor::class)
        val referenceBean = dubboContext.referenceBeans.find {it.`interface` == clazzName}
        return referenceBean?.get() as T
    }
}